package com.example.springboot.exception;

import com.example.springboot.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author:Domen
 * @Date:2023/11/14 17:25
 */
@Slf4j
@RestControllerAdvice
public class ExceptionHandel {

    //自定义全局异常处理，用于捕获全局异常
    @ExceptionHandler(value = ServiceException.class)      // TODO: 2023/11/14  这段注解不懂
    public Result serviceExceptionError(ServiceException e){
        log.error("业务异常", e);
        return Result.error(e.getMessage());
    }

    //自定义全局异常处理，用于捕获全局异常
    @ExceptionHandler(value = Exception.class)      // TODO: 2023/11/14  这段注解不懂
    public Result exceptionError(Exception e){
        log.error("系统错误", e);
        return Result.error("系统错误");
    }

}
